package com.groupbuying.store.pojo;


import com.groupbuying.store.utils.MessageHelper;

/**
 * @anthor wenguoqiang
 * @date: 2019/02/22 10:19
 * @company 够样
 * @des
 **/
public class YspayConfig {

    private static final String absolutePathOFF = "off"; // 绝对路径关闭
    private static String fixPath;

    public static final String absolutePathFlag = "on";// MessageHelper.getMessage("absolutePathFlag");

    // 使用商户自己的私钥签名请求时，采用的字符编码
    public static final String DEFAULT_CHARSET = getAbsolutePath(MessageHelper.getMessage("DEFAULT_CHARSET"));
    // 合作商家私钥pkcs12证书密码
    public static final String PASSWORD_PARTNER_PKCS12 = getAbsolutePath(MessageHelper.getMessage("PASSWORD_PARTNER_PKCS12"));
    // rsa算法名
    public static final String RSA_ALGORITHM = getAbsolutePath(MessageHelper.getMessage("RSA_ALGORITHM"));
    // 合作商家私钥pkcs12证书路径
    public static final String PATH_PARTER_PKCS12 = getAbsolutePath(MessageHelper.getMessage("PATH_PARTER_PKCS12"));
    //代付商家私钥
    public static final String PATH_PARTER_PKCS12_DF = getAbsolutePath(MessageHelper.getMessage("PATH_PARTER_PKCS12_DF"));
    // 银盛公钥pkcs12证书路径
    public static final String PATH_YSEPAY_PUBLIC_CERT = getAbsolutePath(MessageHelper.getMessage("PATH_YSEPAY_PUBLIC_CERT"));
    // 银盛支付接入网关url
    public static final String YSEPAY_GATEWAY_URL = getAbsolutePath(MessageHelper.getMessage("YSEPAY_GATEWAY_URL"));
    // 代付url
    public static final String YSEPAY_GATEWAY_URL_DF = getAbsolutePath(MessageHelper.getMessage("YSEPAY_GATEWAY_URL_DF"));
    // 代付查询url
    public static final String YSEPAY_GATEWAY_URL_SEARCH = getAbsolutePath(MessageHelper.getMessage("YSEPAY_GATEWAY_URL_SEARCH"));
    //代付查询
    public static final String YSEPAY_GATEWAY_URL_DF_SEARCH = getAbsolutePath(MessageHelper.getMessage("YSEPAY_GATEWAY_URL_DF_SEARCH"));
    // 代收url
    public static final String YSEPAY_GATEWAY_URL_DS = getAbsolutePath(MessageHelper.getMessage("YSEPAY_GATEWAY_URL_DS"));
    //分账url
    public static final String YSEPAY_GATEWAY_URL_DSF = getAbsolutePath(MessageHelper.getMessage("YSEPAY_GATEWAY_URL_DSF"));
    // 版本号
    public static final String VERSION = getAbsolutePath(MessageHelper.getMessage("VERSION"));
    // 签名算法
    public static final String SIGN_ALGORITHM = getAbsolutePath(MessageHelper.getMessage("SIGN_ALGORITHM"));
    // 银盛支付服务器主动通知商户网站里指定的页面http路径。
    public static final String NOTIFY_URL = getAbsolutePath(MessageHelper.getMessage("NOTIFY_URL"));
    // 银盛支付支付宝服务器主动通知商户网站里指定的页面http路径。
    public static final String RETURN_ALIPAY_URL = getAbsolutePath(MessageHelper.getMessage("RETURN_ALIPAY_URL"));
    // 银盛支付支付宝服务器主动通知商户网站里指定的页面http路径。
    public static final String NOTIFY_ALPAY_URL = getAbsolutePath(MessageHelper.getMessage("NOTIFY_ALPAY_URL"));
    // 银盛支付服务器主动通知商户网站里指定的页面http路径。
    public static final String NOTIFY_DF_URL = getAbsolutePath(MessageHelper.getMessage("NOTIFY_DF_URL"));
    //银盛支付普通提现回调地址
    public static final String NOTIFY_TX_URL = getAbsolutePath(MessageHelper.getMessage("NOTIFY_TX_URL"));
    //分账回调接口
    public static final String NOTIFY_FZ_URL = getAbsolutePath(MessageHelper.getMessage("NOTIFY_FZ_URL"));
    // 银盛支付处理完请求后，当前页面自动跳转到商户网站里指定页面的http路径。
    public static final String RETURN_URL = getAbsolutePath(MessageHelper.getMessage("RETURN_URL"));
    // 商户号 微信 appid
    public static final String APP_H_ID = getAbsolutePath(MessageHelper.getMessage("APP_H_ID"));
    // 商户号 app appid
    public static final String APP_ID = getAbsolutePath(MessageHelper.getMessage("APP_ID"));
    // 商户号
    public static final String PARTNER_ID = getAbsolutePath(MessageHelper.getMessage("PARTNER_ID"));
    // 代付商户号
    public static final String PARTNER_ID_DF = getAbsolutePath(MessageHelper.getMessage("PARTNER_ID_DF"));
    //商户名
    public static final String SELLER_NAME = getAbsolutePath(MessageHelper.getMessage("SELLER_NAME"));
    // 上传图片获取token口令接口
    public static final String YSEPAY_IMAGE_TOKEN_URL = getAbsolutePath(MessageHelper.getMessage("YSEPAY_IMAGE_TOKEN_URL"));
    // 上传图片接口
    public static final String YSEPAY_IMAGE_UP_URL = getAbsolutePath(MessageHelper.getMessage("YSEPAY_IMAGE_UP_URL"));
    //回调接口
    public static final String NOTIFY_REGIST_URL = getAbsolutePath(MessageHelper.getMessage("NOTIFY_REGIST_URL"));
    //主结构号
    public static final String MAIN_ORG_NO = getAbsolutePath(MessageHelper.getMessage("MAIN_ORG_NO"));
    //子机构号
    public static final String ORG_NO = getAbsolutePath(MessageHelper.getMessage("ORG_NO"));

    /**
     * 根据相对路径获取绝对路径
     *
     * @param path
     *            相对路径(相对与classes目录) File.separator 在windows环境下会出问题
     * @return
     */
    private static String getAbsolutePath(String path) {
       // System.out.println("getAbsolutePath=="+path);
        if (absolutePathOFF.equals(absolutePathFlag)) { // 相对路径
            String outPath = fixPath;
            path = path.replaceAll("\\\\", "/");
            path = path.replaceAll("/\\./", "/");
            if (path.startsWith("./"))
                path = path.substring(2);
            if (path.startsWith("/"))
                path = path.substring(1);
            if (path.startsWith("../")) {
                String[] inStr = path.split("\\.\\./");
                int count = inStr.length - 1;// 向上多少级目录
                // String[] fixStr = fixPath.split(File.separator);
                int i = 0;
                while (i <= count) {
                    int lastFirst = outPath.lastIndexOf('/');
                    outPath = outPath.substring(0, lastFirst);
                    i++;
                }
                outPath = outPath + "/" + inStr[count];
            } else {
                outPath = outPath + path;
            }
            System.out.println("outPath=="+path);
            return outPath;
        }
        return path;
    }

    public static void main(String[] args) {

        System.out.println(RSA_ALGORITHM);

    }
}
